App.directive('checkall', function() {
  'use strict';
  
  return {
    restrict: 'A',
    controller: ["$scope", "$element", function($scope, $element){
      
      $element.on('change', function() {
    	  
        var $this = $(this),
            table = $this.parents('table');
        // Make sure to affect only the correct checkbox column
        table.find('tbody > tr > td input[type="checkbox"]')
          .prop('checked', $this.is(':checked'));
        
        // give ng-model a value 
        angular.forEach($scope.tableParams.data, function(data,i){
    		
    		data.checked = $this.is(':checked');
    	});
        
      });
    }]
  };
}).directive('checkone', function() {
  'use strict';
  
  return {
    restrict: 'A',
    controller: ["$scope", "$element", function($scope, $element){
      
      $element.on('change', function() {
        var $this = $(this),
        	checkAll = true,
            table = $this.parents('table');
        // Make sure to affect only the correct checkbox column
        table.find('tbody > tr > td input[type="checkbox"]')
          .each(function(i,obj){
        	  if(!$(obj).is(':checked')){
        		  checkAll = false; 
        	  }
          });
        table.find('thead > tr > th input[type="checkbox"]')
        	.prop("checked", checkAll);
        
        $('#checkBoxAll').prop('checked', checkAll);
      });
    }]
  };
});